﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineMovieTicket.Model;
using OnlineMovieTicket.Services.IServices;
using OnlineMovieTicket.Services.Services;

namespace OnlineMovieTicket.WebForms.Movies
{
    public partial class MovieReview : System.Web.UI.Page
    {
        Model.MovieReview movieReview;
        Model.Movies movie;
        int movieCode;

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                movieCode = Convert.ToInt32(Request.QueryString["MVCode"].ToString());
                IMovieReviewService movieReviewSrv = new MovieReviewService();
                IMoviesService movieSrv = new MoviesService();
                movie = movieSrv.GetMovie(movieCode);
                txtMovieName.Text = movie.MovieName;
                txtReviewDate.Text = DateTime.Today.ToShortDateString();
            }
            catch
            {
                Response.Redirect("/Index.aspx");
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
          
                Model.MovieReview movieReview = new Model.MovieReview();
                movieReview.DetailReview = txtMovieReview.Text;
                movieReview.CustomerName = txtCustomerName.Text;
                movieReview.Email = txtEmail.Text;
                movieReview.MovieCode = movie.MovieCode;
                movieReview.Rating = Convert.ToInt32(ddlRating.SelectedValue);
                movieReview.ReviewDate = Convert.ToDateTime(txtReviewDate.Text);
                IMovieReviewService movieReviewSrv = new MovieReviewService();
                movieReviewSrv.SaveMovieReview(movieReview, 0);

                Response.Redirect("MovieDetails.aspx?MVCode=" + movieCode);
          
            

        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("MovieDetails.aspx?MVCode=" + movieCode);
        }
    }
}